"""Cif template import:
Imports a cif template that can be then used to generate a cif.
A cif template is a list of cif values. The template preserves 
extra lines in the template to help with organisation. Cif 
items are assumed to be mandatory unless followed by a *. Any 
double hash (##) line is removed, while single # comments are 
included."""

import os

class Cif_template_class(object):
    """Class encapsulating the cif template object.
    Takes as an argument the full filename for the cif template."""
    
    def __init__(self, cif_template_fname):
        """Instantiate the class: read in the template and create 
        the template object."""
        self.filename = cif_template_fname
        self.template_list = self.file_to_list(self.filename)
        
    def file_to_list(self):
        """Function to import the template file to a list. Will 
        filter out anything after a double # (##). If a line has 
        a ## and is then completely empty it will not be included."""
        
        template_list = []
        template_open = open(self.filename, 'r')
        for line in template_open:
            if line == '':
                template_list.append('')
            elif line.startwith('##'):
                pass
            else:
                template_list.append(line.split('##')[0])
                
                
        return template_list
    
